package com.tomato.thread.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import static java.text.MessageFormat.format;


public class CacheThreadPoolOOM {
    public static void main(String[] args) {
        ExecutorService executor = Executors.newCachedThreadPool();
        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            executor.execute(() -> {
                try {
                    Thread.sleep(50_000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(format("{0}执行任务完成", Thread.currentThread().getName()));
            });
        }
    }
}
